package com.ruoyi.web.controller.fuwu;

import java.util.List;

import com.ruoyi.system.service.IWashcarService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Washcar;
import com.ruoyi.framework.web.base.BaseController;
import com.ruoyi.common.page.TableDataInfo;
import com.ruoyi.common.base.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 洗车服务 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-07-16
 */
@Controller
@RequestMapping("/system/washcar")
public class WashcarController extends BaseController
{
    private String prefix = "system/washcar";
	
	@Autowired
	private IWashcarService washcarService;
	
	@RequiresPermissions("system:washcar:view")
	@GetMapping()
	public String washcar()
	{
	    return prefix + "/washcar";
	}
	
	/**
	 * 查询洗车服务列表
	 */
	@RequiresPermissions("system:washcar:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Washcar washcar)
	{
		startPage();
        List<Washcar> list = washcarService.selectWashcarList(washcar);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出洗车服务列表
	 */
	@RequiresPermissions("system:washcar:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Washcar washcar)
    {
    	List<Washcar> list = washcarService.selectWashcarList(washcar);
        ExcelUtil<Washcar> util = new ExcelUtil<Washcar>(Washcar.class);
        return util.exportExcel(list, "washcar");
    }
	
	/**
	 * 新增洗车服务
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存洗车服务
	 */
	@RequiresPermissions("system:washcar:add")
	@Log(title = "洗车服务", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Washcar washcar)
	{		
		return toAjax(washcarService.insertWashcar(washcar));
	}

	/**
	 * 修改洗车服务
	 */
	@GetMapping("/edit/{washcarId}")
	public String edit(@PathVariable("washcarId") Integer washcarId, ModelMap mmap)
	{
		Washcar washcar = washcarService.selectWashcarById(washcarId);
		mmap.put("washcar", washcar);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存洗车服务
	 */
	@RequiresPermissions("system:washcar:edit")
	@Log(title = "洗车服务", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Washcar washcar)
	{		
		return toAjax(washcarService.updateWashcar(washcar));
	}
	
	/**
	 * 删除洗车服务
	 */
	@RequiresPermissions("system:washcar:remove")
	@Log(title = "洗车服务", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(washcarService.deleteWashcarByIds(ids));
	}

	/**
	 * 修改洗车服务状态
	 * @param washcar
	 * @return
	 */
	@Log(title = "洗车服务", businessType = BusinessType.UPDATE)
	@RequiresPermissions("system:washcar:edit")
	@PostMapping("/changeStatus")
	@ResponseBody
	public AjaxResult changeStatus(Washcar washcar)
	{
		return toAjax(washcarService.updateWashcar(washcar));
	}
	
}
